package com.kiven.xml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class ReadXml {
	public static void main(String[] args) {
		SAXBuilder builder = new SAXBuilder(false);
		Document doc = null;
		try {
			doc = builder.build(new FileInputStream("/home/lijianbo/kivenTest/status.xml"));
			List list = doc.getRootElement().getChildren("level");
			Iterator iter = list.iterator();
			
			Element element = null;
			String levelValue = null;
			while(iter.hasNext()) {
				element = (Element)iter.next();
				levelValue = element.getAttributeValue("value");
				
				//取出级别为1对应的所有的文件
				if(levelValue.equals("1")) {
					//下面两种方法取得的值虽然是相同的，但是整个取值的过程是不一样的，根据不用的需求去取才能达到相应的要求。
					System.out.println(element.getChild("top-status").getText());
					System.out.println(element.getChildText("top-status"));
					element.getChild("md5");
				}
				System.out.println(levelValue);
			}
			
			//.getChild("level").getAttributeValue("value");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
